package com.thinkfit.jy.receiver;

import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.common.lib.constant.EventBusEvent;
import com.thinkfit.jy.utils.DialogViewUtils;

import org.greenrobot.eventbus.EventBus;

import java.util.HashMap;

public class BluetoothBroadcastReceiver extends BroadcastReceiver {

    private final String TAG = "BluetoothBroadcastReceiver";

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.e(TAG, "action: " + intent.getAction());
        switch (intent.getAction()){
            case BluetoothDevice.ACTION_ACL_CONNECTED:
                //蓝牙连接
                Log.e(TAG,"onReceive------BluetoothDevice.ACTION_ACL_CONNECTED");
                HashMap<String, Object> map = new HashMap<>();
                map.put(EventBusEvent.BLUETOOTH_CHANGE, true);
                EventBus.getDefault().post(map);
                break;
            case BluetoothDevice.ACTION_ACL_DISCONNECTED:
                //蓝牙连接断开
                Log.e(TAG,"onReceive------BluetoothDevice.ACTION_ACL_DISCONNECTED");
//                DialogViewUtils.getInstance().initView(context,false,DialogViewUtils.BLUETOOTH_DISCONNECTED);
                map = new HashMap<>();
                map.put(EventBusEvent.BLUETOOTH_CHANGE, false);
                EventBus.getDefault().post(map);
                break;
        }
//        EventBus.getDefault().post(intent);
    }
}
